package com.ehualu.javahadoop.service;

import com.ehualu.javahadoop.until.HdfsUntil;
import com.ehualu.javahadoop.until.HiveUntil;
import com.ehualu.javahadoop.until.ReadConfigurationClass;
import com.ehualu.javahadoop.until.Timeuntil;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 吴敬超
 * @Date: 2020/3/3 11:59
 */
@Service
public class SumServiceImpl implements SumService {

    private static Map configmap = ReadConfigurationClass.readConfiguration("application.properties");

    private static String hdfsfapath = configmap.get("hdfspath").toString();

//    private static String hdfsfapath = "hdfs://bigdataha/user/super_rj/hive/textfile/lcgcsj/";

    /*
     *
     * 聊城各个区县的代码
     * */
    private static List<String> qxlist = Arrays.asList(
            "qx=371595",
            "qx=371501",
            "qx=371502",
            "qx=371521",
            "qx=371522",
            "qx=371523",
            "qx=371524",
            "qx=371525",
            "qx=371526",
            "qx=371581",
            "qx=371599");

    @Override
    public Map<String, String> getkknum(String startime, String endtime, String kks) {


        Map<String, String> nums = new HashMap<String, String>();


        String startdt = startime.split(" ")[0];

        String enddt = endtime.split(" ")[0];

        System.out.println("startdt:" + startdt);

        System.out.println("enddt:" + enddt);

        Timeuntil timeuntil = new Timeuntil();
        List<String> listdays = timeuntil.getDays(startime, endtime);

        /*
         *
         * 修复hdfs文件，让查询精准
         * */
        try {
            HdfsUntil hdfsUntil = new HdfsUntil();

            for (String listday : listdays) {
//dt=20190801

                String dtpath = hdfsfapath + "dt=" + listday + "/";

                hdfsUntil.recover(dtpath, qxlist);

            }

        } catch (IOException e) {
            e.printStackTrace();
        }

        HiveUntil hiveUntil = new HiveUntil();
        String strdays = timeuntil.getDaysstr(listdays);

        nums = hiveUntil.hivenum(strdays, startime, endtime, kks);

        return nums;

    }
}
